package com.sdry.web.controller.zc.quality;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.llm.Department;
import com.sdry.model.llm.User;
import com.sdry.model.zc.AbnormalDisposalCraft;
import com.sdry.model.zc.ChangeNotice;
import com.sdry.service.zc.AbnormalDisposalCraftService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

/**
 * @ClassName: AbnormalDisposalCraftController 
 * @Description:生产异常处置单工艺详情Controller
 * @Author zc
 * @Date 2018年11月2日 下午4:12:04 
 * @version 1.0
 */
@RequestMapping(value="/abnormalDisposalCraft")
@Controller
public class AbnormalDisposalCraftController {

	@Resource
	private AbnormalDisposalCraftService abnormalDisposalCraftService;
	
	/**
	 * 查询生产异常处置单工艺详情
	 * @param abnormalDisposalCraft
	 * @param response
	 */
	@RequestMapping(value="/findAbnormalDisposalCraftByAdID")
	public void findAbnormalDisposalCraftByAdID(AbnormalDisposalCraft abnormalDisposalCraft,HttpServletResponse response){
		AbnormalDisposalCraft abnormalDisposalCraft2 = abnormalDisposalCraftService.findAbnormalDisposalCraftByAdID(abnormalDisposalCraft);
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(abnormalDisposalCraft2, jsonConfig);
		try {
			ResponseUtil.write(response, jsonArray);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 保存生产异常处置单工艺详情
	 * @param abnormalDisposalCraft
	 * @param response
	 */
	@RequestMapping(value="/saveAbnormalDisposalCraft")
	public void saveAbnormalDisposalCraft(AbnormalDisposalCraft abnormalDisposalCraft,ChangeNotice changeNotice,HttpServletResponse response,HttpSession session){
		int isSuccess = 0;
		User user = (User) session.getAttribute("currentUser");
		Department department = (Department) session.getAttribute("department");
		abnormalDisposalCraft.setCraftMan(user.getUserName());
		changeNotice.setDraftPerson(user.getUserName());
		changeNotice.setDraftDepartment(department.getName());
		isSuccess = abnormalDisposalCraftService.insertAbnormalDisposalCraft(abnormalDisposalCraft,changeNotice);
		try {
			ResponseUtil.write(response, isSuccess);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
